//
// Created by Ge on 2024/3/5.
//
#include "include/ShareLoader.h"
#include <GLES2/gl2.h>
#include "include/LogUts.h"
#include <stdlib.h>
GLuint loadShader(GLenum shaderType, const char *shaderSource){
    // 创建着色器
    GLuint shader = glCreateShader(shaderType);
    if (shader) {
        // 加载着色器源码
        glShaderSource(shader, 1, &shaderSource, NULL);
        // 编译着色器
        glCompileShader(shader);
        GLint compiled = 0;
        glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
        if (!compiled) {
            GLint infoLen = 0;
            glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
            if (infoLen) {
                char *buf = (char *) malloc(infoLen);
                if (buf) {
                    glGetShaderInfoLog(shader, infoLen, NULL, buf);
                    LOGE("创建着色器失败 shader:\n%s\n", buf);
                    free(buf);
                }
            }
            glDeleteShader(shader);
            shader = 0;
        }
    }
    return shader;
}
